#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from datetime import datetime
from email.policy import default
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime, Enum
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy.orm import relationship
from db.database import Base
from common.utils import formatter


class User(Base):
    __tablename__ = 'user'

    user_id = Column(INTEGER(11), primary_key=True)
    username = Column(String(255))
    name = Column(String(100), nullable=False)
    role = Column(Enum('teacher', 'student', 'admin'), nullable=False)
    email = Column(String(100))
    phone = Column(String(20))
    pic_url = Column(String(255))
    password = Column(String(255))
    class_id = Column(INTEGER(11))

    def __init__(self, username,name, password, phone, role,
                 email):
        self.username = username
        self.name = name
        self.password = password
        self.role = role
        self.email = email
        self.phone = phone

    def __repr__(self):
        return 'User:%s' % self.name

    def to_dict(self):
        new_dict = {}
        for c in self.__table__.columns:
            new_dict[formatter(c.name)] = getattr(self, c.name, None)
        return new_dict
